package com.huawei.appmarket.service.infoflow.cards.node;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout.LayoutParams;
import androidx.annotation.NonNull;
import androidx.databinding.ViewDataBinding;
import com.huawei.appgallery.foundation.ui.framework.widget.Space;
import com.huawei.appmarket.service.infoflow.cards.card.BaseInfoFlowCard;
import com.huawei.appmarket.service.infoflow.view.widget.InfoFlowCardContainer;
import o.azb;
import o.cdr;
import o.chm;
import o.cih;
import o.eah;
import o.epr;
import o.jm;

public abstract class BaseInfoFlowNode extends cdr {
    private int ˊ;
    private InfoFlowCardContainer ᐝ;

    protected abstract int ˋ();

    @NonNull
    protected abstract BaseInfoFlowCard ˎ();

    public BaseInfoFlowNode(Context context) {
        super(context, 1);
        ᐝ();
    }

    public boolean ˊ(ViewGroup viewGroup, ViewGroup viewGroup2) {
        for (int i = 0; i < this.ʼ; i++) {
            if (i != 0) {
                ˏ(new Space(this.ॱ), new LayoutParams(chm.ॱ().ˎ(), -1));
            }
            ViewDataBinding ᐝॱ = ᐝॱ();
            View ॱ = ᐝॱ.ॱ();
            ˏ(i, ॱ);
            cih ˋ = ˋ(ॱ, ᐝॱ);
            LayoutParams layoutParams = new LayoutParams(-1, -2);
            layoutParams.weight = 1.0f;
            ˏ(ॱ, layoutParams);
            ˊ(ˋ);
        }
        viewGroup.addView(this.ᐝ, new LayoutParams(-1, -2));
        return true;
    }

    private void ˏ(int i, View view) {
        int i2;
        int i3 = 0;
        int paddingTop = view.getPaddingTop();
        int paddingBottom = view.getPaddingBottom();
        if (this.ʼ == 1) {
            i2 = this.ˊ;
            i3 = this.ˊ;
        } else if (i == 0) {
            i2 = this.ˊ;
        } else if (i == this.ʼ - 1) {
            i2 = 0;
            i3 = this.ˊ;
        } else {
            i2 = 0;
        }
        view.setPaddingRelative(i2, paddingTop, i3, paddingBottom);
    }

    private BaseInfoFlowCard ˋ(View view, ViewDataBinding viewDataBinding) {
        int ˏ;
        if (epr.ˎ().ॱॱ()) {
            ˏ = eah.ˋ().ˏ(this.ॱ);
        } else if (azb.ˎ(this.ॱ)) {
            ˏ = eah.ˋ().ॱ(this.ॱ);
        } else {
            ˏ = eah.ˋ().ˋ(this.ॱ);
        }
        ˏ = (((ˏ - azb.ᐝ(this.ॱ)) - azb.ʽ(this.ॱ)) - (chm.ॱ().ˎ() * (this.ʼ - 1))) / this.ʼ;
        BaseInfoFlowCard ˎ = ˎ();
        ˎ.ॱ(ˏ);
        ˎ.ˊ(viewDataBinding);
        ˎ.ʽ(view);
        ˎ.ˎ(this.ᐝ);
        return ˎ;
    }

    private void ˏ(@NonNull View view, LayoutParams layoutParams) {
        if (this.ᐝ != null && view != null) {
            this.ᐝ.ˋ(view, layoutParams);
        }
    }

    @NonNull
    private ViewDataBinding ᐝॱ() {
        return jm.ˎ(LayoutInflater.from(this.ॱ), ˋ(), this.ᐝ.ˎ(), false);
    }

    protected void ᐝ() {
        ॱˋ();
        ʻॱ();
        this.ᐝ = new InfoFlowCardContainer(this.ॱ);
    }

    protected int ॱᐝ() {
        return 1;
    }

    protected int ʼ() {
        return 1;
    }

    private void ॱˋ() {
        this.ʼ = epr.ˎ().ॱॱ() ? ʼ() : ॱᐝ();
    }

    protected void ʻॱ() {
        if (epr.ˎ().ॱॱ()) {
            this.ˊ = azb.ˊ(this.ॱ);
            return;
        }
        this.ˊ = 0;
        if (!azb.ˎ(this.ॱ)) {
            this.ˊ = azb.ˊ(this.ॱ);
        }
    }
}
